package org.tp;

import java_cup.runtime.*;
import java.io.*;

%%
%class TpLexer
%line
%column
%cupsym TpSymbol
%cup

%{
private Symbol symbol (int type) {
    return new Symbol (type, yyline, yycolumn);
}

private Symbol symbol (int type, Object value) {
    return new Symbol (type, yyline, yycolumn, value);
}
%}

Identifier	= [a-zA-Z][a-zA-Z0-9_]*
LineTerminator	= \r|\n|\r\n
WhiteSpace	= {LineTerminator} | [ \t\f]
Integer		= [0-9]+
Float		= [0-9]+.[0-9]+
Boolean		= "true"|"false"
String		= \"[^\"]*\"

%xstates MULTI_COM

%%

/* -------------------------------------------------
	Separateurs Operateurs
   ------------------------------------------------- */

"("		{/*System.out.print(yytext());*/  return symbol(TpSymbol.LPAR); }
")"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.RPAR); }
"{"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.LBRACE); }
"}"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.RBRACE); }
"["		{/*System.out.print(yytext());*/  return symbol(TpSymbol.LBRACKET); }
"]"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.RBRACKET); }
"&&"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.AND); }
"||"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.OR); }
"<"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.LT); }
">"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.GT); }
"<="		{/*System.out.print(yytext());*/  return symbol(TpSymbol.LE); }
">="		{/*System.out.print(yytext());*/  return symbol(TpSymbol.GE); }
"!="		{/*System.out.print(yytext());*/  return symbol(TpSymbol.DIFF); }
"=="		{/*System.out.print(yytext());*/  return symbol(TpSymbol.EQ); }
"+"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.PLUS); }
"-"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.MINUS); }
"*"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.MULT); }

"/"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.DIV); }
":="		{/*System.out.print(yytext());*/  return symbol(TpSymbol.AFF); }
"="		{/*System.out.print(yytext());*/  return symbol(TpSymbol.AFF_CONST); }
":"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.COLON); }
","		{/*System.out.print(yytext());*/  return symbol(TpSymbol.COMMA); }
";"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.SEMIC); }

"int"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.TYPE_INT); }
"float"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.TYPE_FLOAT); }
"bool"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.TYPE_BOOL); }
"char"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.TYPE_CHAR); }
"string"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.TYPE_STRING); }

"if"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.IF); }
"else"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.ELSE); }
"repeat" 	{/*System.out.print(yytext());*/  return symbol(TpSymbol.REPEAT); }
"while"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.WHILE); }
"for"	 	{/*System.out.print(yytext());*/  return symbol(TpSymbol.FOR); }
"in" 		{/*System.out.print(yytext());*/  return symbol(TpSymbol.IN); }
".."		{/*System.out.print(yytext());*/  return symbol(TpSymbol.DOUBLE_DOT); }


"procedure" 	{/*System.out.print(yytext());*/  return symbol(TpSymbol.PROCEDURE); }
"function" 	{/*System.out.print(yytext());*/  return symbol(TpSymbol.FUNCTION); }
"return"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.RETURN); }

/* -------------------------------------------------
	Variables, Entiers
   ------------------------------------------------- */

{Identifier}	{/*System.out.print(yytext());*/  return symbol(TpSymbol.IDENTIFIER, yytext()); }
{Integer}	{/*System.out.print(yytext());*/  return symbol(TpSymbol.INTEGER, yytext()); }
{Float}		{/*System.out.print(yytext());*/  return symbol(TpSymbol.FLOAT, yytext()); }
{Boolean}	{/*System.out.print(yytext());*/  return symbol(TpSymbol.BOOLEAN, yytext()); }
{String}	{/*System.out.print(yytext());*/  return symbol(TpSymbol.STRINGEXP, yytext().substring(1, yytext().length()-1)); }

/* -------------------------------------------------
	Commentaires - Caracteres non pris en compte
   ------------------------------------------------- */
{WhiteSpace}                   	{ /*System.out.print(yytext());*/  /* ignore */ }
"//".*				{ /* ignore */ }


"/*"				{yybegin(MULTI_COM);}
<MULTI_COM>{
	"*/" 			{yybegin(YYINITIAL);}
	. 			{ /* ignore */ }
}

/* -------------------------------------------------
	Autres signes
   ------------------------------------------------- */
.	{ /* ignore */ }
